package com.changgou.service.impl;

import com.changgou.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpCookie;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;

@Service
public class AuthServiceImpl implements AuthService {
    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 从cookie中获取jit
     * @param request
     * @return
     */
    @Override
    public String getJitFromCookie(ServerHttpRequest request) {
        HttpCookie jit = request.getCookies().getFirst("uid");
        if (jit!=null){
            return jit.getValue();
        }
        return null;
    }

    @Override
    public String getTokenFromRedisByJit(String jit) {
        return redisTemplate.boundValueOps(jit).get();
    }
}